package com.house.config;

import com.house.interceptor.DomainInterceptor;
import com.house.utils.Constant;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: GGP
 * @description:
 * @time: 2023-03-08 10:51
 **/
@Configuration
public class interceptorConfig implements WebMvcConfigurer {

	/**
	 * 重写方法，注册拦截器（InterceptorRegistry）
	 * @param registry
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new DomainInterceptor()).addPathPatterns("/**").excludePathPatterns("/img/**");
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 映射图片保存地址
		registry.addResourceHandler("/img/**")
				.addResourceLocations("file:" + Constant.SAVE_PATH + Constant.RELATIVE_PATH);
	}
}
